<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="响应码：01成功，02失败，响应码仅代表通信状态" prop="returnCode">
      <el-input v-model="dataForm.returnCode" placeholder="响应码：01成功，02失败，响应码仅代表通信状态"></el-input>
    </el-form-item>
    <el-form-item label="返回信息提示" prop="returnMsg">
      <el-input v-model="dataForm.returnMsg" placeholder="返回信息提示"></el-input>
    </el-form-item>
    <el-form-item label="业务结果，01授权成功，02失败03预授权支付中，99该条码暂不支持类型自动匹配" prop="resultCode">
      <el-input v-model="dataForm.resultCode" placeholder="业务结果，01授权成功，02失败03预授权支付中，99该条码暂不支持类型自动匹配"></el-input>
    </el-form-item>
    <el-form-item label="请求类型，010微信 020支付宝" prop="payType">
      <el-input v-model="dataForm.payType" placeholder="请求类型，010微信 020支付宝"></el-input>
    </el-form-item>
    <el-form-item label="商户名称" prop="merchantName">
      <el-input v-model="dataForm.merchantName" placeholder="商户名称"></el-input>
    </el-form-item>
    <el-form-item label="商户号" prop="merchantNo">
      <el-input v-model="dataForm.merchantNo" placeholder="商户号"></el-input>
    </el-form-item>
    <el-form-item label="终端号" prop="terminalId">
      <el-input v-model="dataForm.terminalId" placeholder="终端号"></el-input>
    </el-form-item>
    <el-form-item label="终端流水号" prop="terminalTrace">
      <el-input v-model="dataForm.terminalTrace" placeholder="终端流水号"></el-input>
    </el-form-item>
    <el-form-item label="终端交易时间" prop="terminalTime">
      <el-input v-model="dataForm.terminalTime" placeholder="终端交易时间"></el-input>
    </el-form-item>
    <el-form-item label="金额" prop="totalFee">
      <el-input v-model="dataForm.totalFee" placeholder="金额"></el-input>
    </el-form-item>
    <el-form-item label="退款金额" prop="refundFee">
      <el-input v-model="dataForm.refundFee" placeholder="退款金额"></el-input>
    </el-form-item>
    <el-form-item label="支付完成时间" prop="endTime">
      <el-input v-model="dataForm.endTime" placeholder="支付完成时间"></el-input>
    </el-form-item>
    <el-form-item label="利楚唯一订单号" prop="outTradeNo">
      <el-input v-model="dataForm.outTradeNo" placeholder="利楚唯一订单号"></el-input>
    </el-form-item>
    <el-form-item label="通道订单号，如微信订单号，支付宝订单号等" prop="channelTradeNo">
      <el-input v-model="dataForm.channelTradeNo" placeholder="通道订单号，如微信订单号，支付宝订单号等"></el-input>
    </el-form-item>
    <el-form-item label="银行渠道订单号，微信支付时显示在支付成功页面的条码，可用作扫码查询和扫码退款时匹配" prop="channelOrderNo">
      <el-input v-model="dataForm.channelOrderNo" placeholder="银行渠道订单号，微信支付时显示在支付成功页面的条码，可用作扫码查询和扫码退款时匹配"></el-input>
    </el-form-item>
    <el-form-item label="付款方用户ID" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="付款方用户ID"></el-input>
    </el-form-item>
    <el-form-item label="附加数据" prop="attach">
      <el-input v-model="dataForm.attach" placeholder="附加数据"></el-input>
    </el-form-item>
    <el-form-item label="交易状态" prop="payStatusCode">
      <el-input v-model="dataForm.payStatusCode" placeholder="交易状态"></el-input>
    </el-form-item>
    <el-form-item label="门店名称" prop="storeName">
      <el-input v-model="dataForm.storeName" placeholder="门店名称"></el-input>
    </el-form-item>
    <el-form-item label="签名字符串，拼装所有非空参数，UTF-8编码，32位MD5加密转换" prop="keySign">
      <el-input v-model="dataForm.keySign" placeholder="签名字符串，拼装所有非空参数，UTF-8编码，32位MD5加密转换"></el-input>
    </el-form-item>
    <el-form-item label="操作员" prop="operator">
      <el-input v-model="dataForm.operator" placeholder="操作员"></el-input>
    </el-form-item>
    <el-form-item label="支付款项ID" prop="checkinAccountingId">
      <el-input v-model="dataForm.checkinAccountingId" placeholder="支付款项ID"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          returnCode: '',
          returnMsg: '',
          resultCode: '',
          payType: '',
          merchantName: '',
          merchantNo: '',
          terminalId: '',
          terminalTrace: '',
          terminalTime: '',
          totalFee: '',
          refundFee: '',
          endTime: '',
          outTradeNo: '',
          channelTradeNo: '',
          channelOrderNo: '',
          userId: '',
          attach: '',
          payStatusCode: '',
          storeName: '',
          keySign: '',
          operator: '',
          checkinAccountingId: ''
        },
        dataRule: {
          returnCode: [
            { required: true, message: '响应码：01成功，02失败，响应码仅代表通信状态不能为空', trigger: 'blur' }
          ],
          returnMsg: [
            { required: true, message: '返回信息提示不能为空', trigger: 'blur' }
          ],
          resultCode: [
            { required: true, message: '业务结果，01授权成功，02失败03预授权支付中，99该条码暂不支持类型自动匹配不能为空', trigger: 'blur' }
          ],
          payType: [
            { required: true, message: '请求类型，010微信 020支付宝不能为空', trigger: 'blur' }
          ],
          merchantName: [
            { required: true, message: '商户名称不能为空', trigger: 'blur' }
          ],
          merchantNo: [
            { required: true, message: '商户号不能为空', trigger: 'blur' }
          ],
          terminalId: [
            { required: true, message: '终端号不能为空', trigger: 'blur' }
          ],
          terminalTrace: [
            { required: true, message: '终端流水号不能为空', trigger: 'blur' }
          ],
          terminalTime: [
            { required: true, message: '终端交易时间不能为空', trigger: 'blur' }
          ],
          totalFee: [
            { required: true, message: '金额不能为空', trigger: 'blur' }
          ],
          refundFee: [
            { required: true, message: '退款金额不能为空', trigger: 'blur' }
          ],
          endTime: [
            { required: true, message: '支付完成时间不能为空', trigger: 'blur' }
          ],
          outTradeNo: [
            { required: true, message: '利楚唯一订单号不能为空', trigger: 'blur' }
          ],
          channelTradeNo: [
            { required: true, message: '通道订单号，如微信订单号，支付宝订单号等不能为空', trigger: 'blur' }
          ],
          channelOrderNo: [
            { required: true, message: '银行渠道订单号，微信支付时显示在支付成功页面的条码，可用作扫码查询和扫码退款时匹配不能为空', trigger: 'blur' }
          ],
          userId: [
            { required: true, message: '付款方用户ID不能为空', trigger: 'blur' }
          ],
          attach: [
            { required: true, message: '附加数据不能为空', trigger: 'blur' }
          ],
          payStatusCode: [
            { required: true, message: '交易状态不能为空', trigger: 'blur' }
          ],
          storeName: [
            { required: true, message: '门店名称不能为空', trigger: 'blur' }
          ],
          keySign: [
            { required: true, message: '签名字符串，拼装所有非空参数，UTF-8编码，32位MD5加密转换不能为空', trigger: 'blur' }
          ],
          operator: [
            { required: true, message: '操作员不能为空', trigger: 'blur' }
          ],
          checkinAccountingId: [
            { required: true, message: '支付款项ID不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/hotel/thotelpreauthbarresult/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.returnCode = data.tHotelPreauthbarResult.returnCode
                this.dataForm.returnMsg = data.tHotelPreauthbarResult.returnMsg
                this.dataForm.resultCode = data.tHotelPreauthbarResult.resultCode
                this.dataForm.payType = data.tHotelPreauthbarResult.payType
                this.dataForm.merchantName = data.tHotelPreauthbarResult.merchantName
                this.dataForm.merchantNo = data.tHotelPreauthbarResult.merchantNo
                this.dataForm.terminalId = data.tHotelPreauthbarResult.terminalId
                this.dataForm.terminalTrace = data.tHotelPreauthbarResult.terminalTrace
                this.dataForm.terminalTime = data.tHotelPreauthbarResult.terminalTime
                this.dataForm.totalFee = data.tHotelPreauthbarResult.totalFee
                this.dataForm.refundFee = data.tHotelPreauthbarResult.refundFee
                this.dataForm.endTime = data.tHotelPreauthbarResult.endTime
                this.dataForm.outTradeNo = data.tHotelPreauthbarResult.outTradeNo
                this.dataForm.channelTradeNo = data.tHotelPreauthbarResult.channelTradeNo
                this.dataForm.channelOrderNo = data.tHotelPreauthbarResult.channelOrderNo
                this.dataForm.userId = data.tHotelPreauthbarResult.userId
                this.dataForm.attach = data.tHotelPreauthbarResult.attach
                this.dataForm.payStatusCode = data.tHotelPreauthbarResult.payStatusCode
                this.dataForm.storeName = data.tHotelPreauthbarResult.storeName
                this.dataForm.keySign = data.tHotelPreauthbarResult.keySign
                this.dataForm.operator = data.tHotelPreauthbarResult.operator
                this.dataForm.checkinAccountingId = data.tHotelPreauthbarResult.checkinAccountingId
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/hotel/thotelpreauthbarresult/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'returnCode': this.dataForm.returnCode,
                'returnMsg': this.dataForm.returnMsg,
                'resultCode': this.dataForm.resultCode,
                'payType': this.dataForm.payType,
                'merchantName': this.dataForm.merchantName,
                'merchantNo': this.dataForm.merchantNo,
                'terminalId': this.dataForm.terminalId,
                'terminalTrace': this.dataForm.terminalTrace,
                'terminalTime': this.dataForm.terminalTime,
                'totalFee': this.dataForm.totalFee,
                'refundFee': this.dataForm.refundFee,
                'endTime': this.dataForm.endTime,
                'outTradeNo': this.dataForm.outTradeNo,
                'channelTradeNo': this.dataForm.channelTradeNo,
                'channelOrderNo': this.dataForm.channelOrderNo,
                'userId': this.dataForm.userId,
                'attach': this.dataForm.attach,
                'payStatusCode': this.dataForm.payStatusCode,
                'storeName': this.dataForm.storeName,
                'keySign': this.dataForm.keySign,
                'operator': this.dataForm.operator,
                'checkinAccountingId': this.dataForm.checkinAccountingId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
